package com.qms.tubu.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.qms.tubu.R;


/**
 * Created by youyi on 2015/4/11.
 */
public class LoadLayout extends FrameLayout{
    private View mProgress;
    public LoadLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        mProgress= LayoutInflater.from(this.getContext()).inflate(R.layout.load_progress,null);
        LayoutParams params=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        mProgress.setLayoutParams(params);
        this.addView(mProgress);
        finishLoad();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev);
    }

    public void startLoad()
    {
        mProgress.setVisibility(View.VISIBLE);
    }
    public void finishLoad()
    {
        mProgress.setVisibility(View.GONE);
    }
//    private class LoadView extends View {
//        private Paint paint;
//        private int pos;
//        public LoadView(Context context) {
//            super(context);
//            this.setBackgroundColor(getResources().getColor(R.color.load_bg));
//            this.setClickable(true);
//            paint=new Paint(Paint.ANTI_ALIAS_FLAG);
//            paint.setStyle(Paint.Style.FILL);
//            paint.setColor(Color.WHITE);
//            pos=0;
//        }
//
//        @Override
//        protected void onDraw(Canvas canvas) {
//            super.onDraw(canvas);
//            int halfWidth=this.getWidth()/2;
//            int halfHeight=this.getHeight()/2;
//            for(int i=0;i<12;i++)
//            {
//                int cx= (int) (Math.sin(Math.toRadians(i*30))*20+halfWidth);
//                int cy= (int) (halfHeight-Math.cos(Math.toRadians(i*30))*20);
//                if(pos==i)
//                    canvas.drawCircle(cx,cy,4,paint);
//                else
//                    canvas.drawCircle(cx,cy,2,paint);
//            }
//            pos++;
//            pos=pos%12;
//            this.postDelayed(new Runnable() {
//                @Override
//                public void run() {
//                    invalidate();
//                }
//            },50);
//        }
//    }

}

